INCLUDES = -I../
WARNINGS = -Wall -g -pedantic
CC = gcc                       
CFLAGS = $(INCLUDES) $(WARNINGS)
CPPFLAGS = $(INCLUDES)

CTXPREFIX=ctxctx
TOKENSSRC=$(shell ls ../*.l)
GRAMMARSRC=$(shell ls ../*.y)


OUTFILE=ctxcalc
SRCSTOTEST=$(shell ls -f ../*.c)
SRCS = ctxcalc.c tokens.c contexts_grammar.c $(SRCSTOTEST) 
OBJS  = $(SRCS:.c=.o)

ctxcalc: grammar tokens dep $(OBJS)
	$(CC) $(CFLAGS) $(SRCS) -o $(OUTFILE)

ifeq (.depend,$(wildcard .depend))
include .depend
endif

dep:
	$(CC) $(CPPFLAGS) -MM $(SRCSTOTEST) > .depend

grammar: $(GRAMMARSRC)
	bison -o contexts_grammar.c -d -p $(CTXPREFIX) $(GRAMMARSRC)

tokens: $(GRAMMARSRC) $(TOKENSSRC) 
	flex -otokens.c -P$(CTXPREFIX) $(TOKENSSRC)

clean:
	rm *.o


doc:
	doxygen Doxyfile
